﻿using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Options;
using System;
using Volo.Abp.EntityFrameworkCore;
using Volo.Abp.Modularity;

namespace Himp.Outpatient.EntityFrameworkCore;

[DependsOn(
    typeof(OutpatientDomainModule),
    typeof(AbpEntityFrameworkCoreModule)
)]
public class OutpatientEntityFrameworkCoreModule : AbpModule
{
    public override void PreConfigureServices(ServiceConfigurationContext context)
    {
        AppContext.SetSwitch("Npgsql.EnableLegacyTimestampBehavior", true);
    }

    public override void ConfigureServices(ServiceConfigurationContext context)
    {
        context.Services.AddAbpDbContext<OutpatientDbContext>(options =>
        {
            options.AddDefaultRepositories(includeAllEntities: true);

            options.Entity<OtpSchdPlan>(opt =>
            {
                opt.DefaultWithDetailsFunc = q => { return q.Include(p => p.OtpSchdType); };
            });

            options.Entity<OtpSchdPlan>(opt =>
            {
                opt.DefaultWithDetailsFunc = q => { return q.Include(p => p.OtpSchdPeriods); };
            });

            options.Entity<OtpSchdRec>(opt =>
            {
                opt.DefaultWithDetailsFunc = q => { return q.Include(p => p.OtpSchdPlan).Include(p=>p.OtpSchdPeriod); };
            });

            #region 门诊就诊

            options.Entity<OtpRxRec>(opt =>
            {
                opt.DefaultWithDetailsFunc = q => { return q.Include(p => p.OtpRxRecDetls); };
            });

            #endregion
        });
    }
}
